﻿using UnityEngine;

public static class PCRFormula
{
    /// <summary>
    /// 是否闪避
    /// </summary>
    /// <param name="targetEvasion"></param>
    /// <param name="sourceHit"></param>
    /// <returns></returns>
    public static bool IsMiss(float targetEvasion, float sourceHit)
    {
        return Random.value <= 1f / (1f + 100f / (targetEvasion - sourceHit));
    }

    /// <summary>
    /// 是否暴击
    /// </summary>
    /// <param name="targetLevel"></param>
    /// <param name="sourceLevel"></param>
    /// <param name="sourceCritical"></param>
    /// <returns></returns>
    public static bool IsCritical(int targetLevel, int sourceLevel, float sourceCritical)
    {
        return Random.value <= sourceCritical * 0.05f * 0.01f * targetLevel / sourceLevel;
    }

    /// <summary>
    /// 计算伤害
    /// </summary>
    /// <param name="amount"></param>
    /// <param name="targetDefense"></param>
    /// <returns></returns>
    public static float CalculateDamage(float amount, float targetDefense)
    {
        return amount / (1f + targetDefense / 100f);
    }
}